package leecode;

import org.junit.Test;

public class Question206 {

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {

        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        // 4
        ListNode cur = reverseList(head.next);//5
        head.next.next = head;
        head.next = null;
        return cur;
    }
    @Test
    public void main(){
        int[] head = {1, 2, 3, 4, 5};
        ListNode cur = new ListNode(1);
        cur.next = new ListNode(2);
        cur.next.next  = new ListNode(3);
        cur.next.next.next  = new ListNode(4);
        cur.next.next.next.next  = new ListNode(5);

        ListNode list = reverseList(cur);
        while (list.next != null) {
            System.out.println(list.val);
            list = list.next;
        }

    }

}
